
package com.rx.mgt.dao;  

import java.util.List;

import com.rx.mgt.domain.DomainSign;
import com.rx.mgt.domain.SysOpreate;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rx.mgt.dao.base.ManagementHibernateDaoBase;
import com.rx.mgt.domain.Domain;
import com.rx.mgt.domain.DomainInfoExt;
import com.rx.mgt.po.UsersBo;

/** 
 * ClassName:DomainDao 
 * Function :
 * Reason   : 
 * Date     :Feb 1, 2017 10:30:17 AM 
 * @author   luolei 
 * @since    JDK 1.6
 */
@Repository
public class DomainDao  extends ManagementHibernateDaoBase<Domain, String>{
    @Transactional(readOnly=true)
    public List<Domain>  getDomainInfoExt(UsersBo usersBo){
        String hql= "select  new Domain(au.domain_name) from Domain au,DomainInfoExt e where 1=1 and au.domain_name = e.domain ";
        if(StringUtils.isNotBlank(usersBo.getDomain())){
            hql=hql +" and  au.domain_name=:domain";
        }
        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        if(StringUtils.isNotBlank(usersBo.getDomain())){
            query.setParameter("domain", usersBo.getDomain());
        }
        return  query.list();
    }

    @Transactional(readOnly=true)
    public List<Domain>  getDomainInfoExtQy(UsersBo usersBo){
        String hql= "select  new Domain(au.domain_name) from Domain au,DomainInfoExt e where 1=1 and au.domain_name = e.domain and e.type='企业'";
        if(StringUtils.isNotBlank(usersBo.getDomain())){
            hql=hql +" and  au.domain_name=:domain";
        }
        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        if(StringUtils.isNotBlank(usersBo.getDomain())){
            query.setParameter("domain", usersBo.getDomain());
        }
        return  query.list();
    }

    @Transactional
    public  Domain selectDomainByDomain(String domain){
        String hql= "from Domain  dd where 1=1 and  dd.domain_name=:domain";
        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        query.setParameter("domain",domain);
        return (Domain) query.uniqueResult();
    }

    @Transactional
    public DomainSign getDomainSignContentByDomain(String domain) {
        String hql = " from DomainSign d where 1 = 1  and domain=:domain";
        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        query.setParameter("domain",domain);
        return (DomainSign) query.uniqueResult();

    }

    public SysOpreate getSysOpreateByDomain(String domain) {
        String hql = " from SysOpreate s where 1=1 and s.domain=:domain";
        Query domain1 = template.getSessionFactory().getCurrentSession().createQuery(hql).setParameter("domain", domain);
        return (SysOpreate)domain1.uniqueResult();
    }
}
  